$(".search").click(function () {
    var data = $("#searchform").serialize();
    window.location.href = '/admin/member/index?' + data;
});
$(".Download").click(function () {
    var data = $("#searchform").serialize();
    $.ajax({
        url: '/admin/member/excel',
        type: 'POST',
        data:data,
        dataType: 'JSON',
        success:function (res) {
            if(res.status==1){
                location.href =(res.msg);
            }
        }
    })
});

$("#province").on("change",function () {
    var city = $("#province").val();
    $("#area").html("");
    var html = " <option value=''>全部</option>";
    $("#area").append(html);
    getCity(city);
})
$("#city").on("change",function () {
    var city = $("#city").val();
    getArea(city);
})
function getCity(city){
    $.ajax({
        url: 'city',
        data: {city: city},
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            var cityArray =  data.cityArray;
            $("#city").html("");
            var html = " <option value=''>全部</option>";
            $.each(cityArray, function (i, item) {
                html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
            });
            $("#city").append(html);
        }
    })
}

function getArea(area){
    $.ajax({
        url: 'area',
        data: {area: area},
        type: 'POST',
        dataType: 'json',//返回的数据类型
        success: function (data) {
            var cityArray =  data.cityArray;
            $("#area").html("");
            var html = " <option value=''>全部</option>";
            $.each(cityArray, function (i, item) {
                html += "<option value='"+item.district_id+"'>" + item.district + "</option>";
            });
            $("#area").append(html);
        }
    })
}

/**修改用户的状态*/
$("#info_disabled,#info_res,#info_forbidden,#info_recovery").click(function () {
    var act = $(this).attr('id');
    var value = new Array();
    $("tbody span[class='checked'] input").each(function (a, b) {
        value[a] = 'id=' + $(this).val();
    });
    var ids = value.join('&');
    if(act == 'info_forbidden'){
        act = 2;
        var confirm_msg = "确认禁用用户吗";
    }
    if(act =='info_recovery'){
        act = 1;
        var confirm_msg = "确认恢复用户吗";
    }
    if(ids==''){
        dshow('请选择至少一条数据进行操作');
        return false;
    }
    if (confirm(confirm_msg)) {
        $.ajax({
            url: '/admin/member/UpdateUser',
            type: 'POST',
            data: {ids: ids, act: act},
            dataType: 'JSON',
            cache: false,
            success: function (json) {
                dshow(json.message);
                if (json.code == 2000) {
                    window.location.href = '/admin/member/index';
                }
            }
        });
    }
});

$(".look").click(function () {
    var id = $(this).attr('data-id');
    var page = $("input[name='page']").val();
    window.location.href = '/admin/member/look?page=' + page + '&id=' + id;
});

$(".buy").click(function () {
    var id = $(this).attr('data-id');
    var page = $("input[name='page']").val();
    window.location.href = '/admin/member/buy?page=' + page + '&id=' + id;
});
$(".send").click(function () {
    var id = $(this).attr('data-id');
    var page = $("input[name='page']").val();
    window.location.href = '/admin/member/fabu?page=' + page + '&id=' + id;
});

$(".check").click(function () {
    var id = $(this).attr('data-id');
    var page = $("input[name='page']").val();
    window.location.href = '/admin/member/check?page=' + page + '&id=' + id;
});
